/* eslint-disable no-dupe-keys */
<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="姓名" prop="personName">
        <el-input
          v-model="queryParams.personName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别" prop="detectionCycleId">
        <el-select
          v-model="queryParams.detectionCycleId"
          filterable
          placeholder="请选择类别"
        >
          <el-option
            v-for="item in category"
            :key="item.id"
            :label="item.categoryName"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="身份证号码" label-width="100" prop="cardId">
        <el-input
          v-model="queryParams.cardId"
          placeholder="请输入身份证号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属部门">
        <el-cascader
          :options="hangye"
          v-model="queryParams.deptId"
          :show-all-levels="false"
          :props="{ checkStrictly: true, emitPath: false, value: 'id' }"
          clearable
        ></el-cascader>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="personList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        label="姓名"
        align="center"
        prop="personName"
        width="100"
      />
      <el-table-column
        label="类别"
        align="center"
        prop="detectioncycleName"
        width="120"
      >
        <template slot-scope="{ row }">
          {{
            (row.detectionCycleList &&
              row.detectionCycleList.length > 0 &&
              row.detectionCycleList[0].categoryName) ||
            ""
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="身份证号码"
        align="center"
        prop="cardId"
        width="170"
      />
      <el-table-column
        label="手机号码"
        align="center"
        prop="phoneNumber"
        width="150"
      />
      <el-table-column
        label="所属部门"
        align="center"
        prop="deptName"
        width="500"
      />
      <el-table-column
        label="数据来源"
        align="center"
        prop="source"
        width="120"
      >
        <template slot-scope="{ row }">
          {{ row.source | sourceFilter }}
        </template>
      </el-table-column>
      <el-table-column label="删除原因" align="center" prop="reason" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="180"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-hasPermi="['system:person:query']"
            @click="handleKan(scope.row)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 查看 -->
    <el-dialog
      title="查看"
      :visible.sync="open"
      width="500px"
      custom-class="dialog-internal-scroll"
      top="0"
      append-to-body
    >
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="姓名" prop="personName">
          <div>{{ form.personName }}</div>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <div>{{ form.sex }}</div>
        </el-form-item>
        <el-form-item label="年龄" prop="personAge">
          <div>{{ form.personAge }}</div>
        </el-form-item>
        <el-form-item label="类别" prop="detectioncycleName">
          <div>
            {{
              form.detectionCycleList &&
              form.detectionCycleList.length > 0 &&
              form.detectionCycleList[0].categoryName
            }}
          </div>
        </el-form-item>
        <el-form-item label="工作地点" prop="workAddress">
          <div>{{ form.workAddress }}</div>
        </el-form-item>
        <el-form-item label="身份证号码" prop="cardId">
          <div>{{ form.cardId }}</div>
        </el-form-item>
        <el-form-item label="手机号码" prop="phoneNumber">
          <div>{{ form.phoneNumber }}</div>
        </el-form-item>
        <el-form-item label="家庭住址" prop="address">
          <div>{{ form.address }}</div>
        </el-form-item>
        <el-form-item label="所属部门" prop="deptName">
          <div>{{ form.deptName }}</div>
        </el-form-item>
        <el-form-item label="企业名称" prop="enterpriseName">
          <div>{{ form.enterpriseName }}</div>
        </el-form-item>
        <el-form-item label="删除原因" prop="reason">
          <div>{{ form.reason }}</div>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPerson,
  getPerson,
  categorychargelist,
} from "@/api/control/person";
import { getToken } from "@/utils/auth";
import SelectTree from "@/components/selecttree.vue";
import Tree from "@/components/selecttreesech.vue";
import { treeselectrole } from "@/api/control/dept";
export default {
  name: "Person",
  components: {
    SelectTree,
    Tree,
  },
  filters: {
    sourceFilter(status) {
      const statusMap = {
        0: "PC新增",
        1: "PC导入",
        2: "小程序录入",
        3: "经营录入",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      personList: [],
      hangye: [],
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        delFlag: 2,
        openId: null,
        personName: null,
        personAge: null,
        workAddress: null,
        cardId: null,
        phoneNumber: null,
        address: null,
        category: null,
        detectionTime3: null,
        detectionAddress: null,
        detectionNumber: null,
        industry: null,
        enterpriseName: null,
        organization: null,
        // eslint-disable-next-line no-dupe-keys
        category: null,
        deptId: null,
        detectionCycleId: null,
        chargeId: null,
      },
      category: [],
      examinearr: [
        {
          name: "审核通过",
          id: 0,
        },
        {
          name: "未审核",
          id: 1,
        },
      ],
      jiancetype: [
        {
          name: "未检",
          id: 0,
        },
        {
          name: "已检",
          id: 1,
        },
      ],
      // 表单参数
      form: {
        deptId: "",
      },
    };
  },
  created() {
    this.getList();
    this.categorychargeList();
    this.getTreeSelect();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listPerson(this.queryParams).then((response) => {
        this.personList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        personId: null,
        openId: null,
        personName: null,
        personAge: null,
        workAddress: null,
        cardId: null,
        phoneNumber: null,
        address: null,
        category: null,
        detectionTime3: null,
        detectionAddress: null,
        detectionNumber: null,
        industry: null,
        enterpriseName: null,
        createTime: null,
        deptId: null,
        category: null,
        detectionCycleId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.deptId = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.personId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 类别下拉框 */
    categorychargeList() {
      categorychargelist().then((res) => {
        this.category = res.data;
      });
    },
    // 获取所有部门
    getTreeSelect() {
      treeselectrole().then((res) => {
        this.hangye = res.data;
      });
    },
    // 查看
    handleKan(row) {
      this.reset();
      const personId = row.personId || this.ids;
      getPerson(personId).then((response) => {
        this.form = response.data;
        this.open = true;
      });
    },
  },
};
</script>
